<template>
    <el-card>
        <el-row :gutter="5">
            <el-col :md="{span:8}" :sm="{span: 12}">
                <el-input
                        v-model="search.content"
                        placeholder="请输入用户名或者id"
                        class="search-doctor-input"
                >
                    <template #append>
                        <el-button style="width: 100px" @click="LoadPatientDatas(1)">
                            <el-icon>
                                <i class="fas fa-search" />
                            </el-icon>
                            搜索
                        </el-button>
                    </template>
                </el-input>
            </el-col>
            <el-col :md="{span:4}" :sm="{span:4}">
                <el-button type="primary" plain @click="dialog.isShowAddPatient=true">
                    <el-icon>
                        <i class="fas fa-plus" />
                    </el-icon>
                    添加
                </el-button>
            </el-col>
        </el-row>
    </el-card>
    <el-card style="margin-top: 10px">

        <el-table :data="patientDatas" style="width: 100%">
            <el-table-column prop="patientId" label="病患ID" />
            <el-table-column prop="patientName" label="病患姓名"  />
            <el-table-column prop="patientIdnum" label="身份证"  />
            <el-table-column prop="patientSex" label="性别"  />
            <el-table-column fixed="right" label="操作" width="120">
                <template #default="scope">
                    <el-button type="primary" @click="addPrescription(scope.row)">
                        <el-icon>
                            <i class="fas fa-edit" />
                        </el-icon>
                        添加诊断
                    </el-button>

                </template>
            </el-table-column>
        </el-table>
    </el-card>
    <el-card style="margin-top: 10px">
        <el-pagination style="text-align: center" layout="prev, pager, next" :page-size="pageInation.pageSize" :page-count="pageInation.pageCount" @current-change="LoadPatientDatas" small></el-pagination>
    </el-card>
    <el-dialog
            v-model="dialog.isShowAddPatient"
            title="添加患者"
            width="30%"
            destroy-on-close
            center
    >
        <SystemPopupAddPatient />
    </el-dialog>
    <div v-if="dialog.isShowAddPrescription">
        <el-dialog
                v-model="dialog.isShowAddPrescription"
                title="添加用户"
                width="30%"
                center
        >
            <DoctorPopupAddPrescription :row="rowData" />
        </el-dialog>
    </div>
</template>

<script>
    import utils from "@/Utils";
    import SystemPopupAddPatient from "@/components/SystemAdmin/Popup/SystemPopupAddPatient";
    import DoctorPopupAddPrescription from "@/components/Doctor/Popup/DoctorPopupAddPrescription";
    export default {
        name: "DoctorPatient",
        components:{
            SystemPopupAddPatient,
            DoctorPopupAddPrescription
        },
        data(){
            return{
                search:{
                    content:''
                },
                patientDatas:[],
                pageInation:{
                    pageCount:0,
                    pageSize:0,
                },
                loading:true,
                update:{
                    patientSex:''
                },
                dialog:{
                    isShowAddPatient:false,
                    isShowAddPrescription:false
                },
                rowData:{},
                utils
            }
        },
        methods:{
            LoadPatientDatas:async function (pageIndex) {
                await this.axios.post("/Patient/isLogin/isSystemAndDoctor/getPatientBySearch",{
                    pageIndex:pageIndex,
                    pageSize:10,
                    search:this.search.content
                }).then((req)=>{
                    const data=req.data;
                    if(data.code>0){
                        this.utils.tipsMessage(data.error,data.code);
                        return
                    }
                    const pageData=data.data.pageData;
                    this.pageInation.pageSize=data.data.pageSize;
                    this.pageInation.pageCount=data.data.pageCount;
                    this.patientDatas=pageData;
                    this.loading=false
                })
            },
            addPrescription:function (row) {
                this.dialog.isShowAddPrescription=true;
                this.rowData=row;
            }
        },
        mounted(){
            this.LoadPatientDatas(1)
        }
    }
</script>

<style scoped>
    .search-doctor-input /deep/ .el-input-group__prepend,.search-doctor-input /deep/ .el-input-group__append {
        background-color: #fff;
    }
</style>